package com.jspgou.cms.manager.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jspgou.common.hibernate3.Updater;
import com.jspgou.common.page.Pagination;
import com.jspgou.cms.dao.ShipmentsDao;
import com.jspgou.cms.entity.Shipments;
import com.jspgou.cms.manager.ShipmentsMng;

@Service
@Transactional
public class ShipmentsMngImpl implements ShipmentsMng {
	@Transactional(readOnly = true)
	public Pagination getPage(int pageNo, int pageSize) {
		Pagination page = dao.getPage(pageNo, pageSize);
		return page;
	}
	
	public List<Shipments> getList(Long orderId){
		return dao.getList(orderId);
	}
	
	public Shipments findByorderId(Long orderId) {
		return dao.findByorderId(orderId);
	}

	public Pagination getFcList(Long memberId,Long storeId,int pageNo,int pageSize) {
		return dao.getFcList(memberId,storeId,pageNo,pageSize);
	}
	
	public void deleteByorderId(Long orderId){
		List<Shipments> list=getList(orderId);
		for(Shipments shipments:list){
			deleteById(shipments.getId());
		}
	}
	
	@Transactional(readOnly = true)
	public Shipments findById(Long id) {
		Shipments entity = dao.findById(id);
		return entity;
	}

	public Shipments save(Shipments bean) {
		dao.save(bean);
		return bean;
	}

	public Shipments update(Shipments bean) {
		Updater<Shipments> updater = new Updater<Shipments>(bean);
		Shipments entity = dao.updateByUpdater(updater);
		return entity;
	}

	public Shipments deleteById(Long id) {
		Shipments bean = dao.deleteById(id);
		return bean;
	}
	
	public Shipments[] deleteByIds(Long[] ids) {
		Shipments[] beans = new Shipments[ids.length];
		for (int i = 0,len = ids.length; i < len; i++) {
			beans[i] = deleteById(ids[i]);
		}
		return beans;
	}

	private ShipmentsDao dao;

	@Autowired
	public void setDao(ShipmentsDao dao) {
		this.dao = dao;
	}
}